package com.esaheki.flashcards.uiSupport;

import java.sql.SQLException;
import java.util.ArrayList;

import com.esaheki.flashcards.classes.*;
import com.esaheki.flashcards.dao.*;


/**
 * CardList mantem a lista de cartas de acordo com o objeto que seu construtor
 * receber, o que pode ser a lista de cartas de uma categoria, de um usuario
 * ou todas as cartas do banco de dados.
 * 
 * @author      Elton Saheki Horikoshi <esaheki@gmail.com>
 */
public class CardList {
	
	private Object obj;
	
	public CardList () {
	}
	
	public CardList (Object obj) {
    	this.obj = obj;
	}
	
	public ArrayList<Card> getCardList() {
		ArrayList<Card> cardlist = new ArrayList<Card>();
		try {
			CardDAO cDao = new CardDAO();

			if (obj instanceof Category) {
				cardlist = cDao.getCardListByCategory((Category) obj);
			}
			else if (obj instanceof User) {
				cardlist = cDao.getCardListByUser((User) obj);
			}
			else if (obj instanceof ArrayList<?>) {
				cardlist = cDao.getAllCardList();
			}
			else if (obj == null) {
				cardlist = cDao.getAllCardList();
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			return null;
		}

		return cardlist;
	}

}
